package com.cx.controller;

import com.cx.dto.HotelFacilitiy;
import com.cx.dto.HotelInfo;
import com.cx.dto.HotelPolicy;
import com.cx.dto.RecentHotel;
import com.cx.pojo.HotelComment;
import com.cx.service.HotelFacilitiesMapperService;
import com.cx.service.HotelMapperService;
import com.cx.service.HotelPolicyMapperService;
import com.cx.service.impl.CommentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Controller
public class HotelInfoController {
    @Autowired
    HotelMapperService hotelMapperService;
    @Autowired
    HotelPolicyMapperService hotelPolicyMapperService;
    @Autowired
    HotelFacilitiesMapperService hotelFacilitiesMapperService;
    @Autowired
    private CommentDao commentDao;
    @ResponseBody
    @RequestMapping("hotelinfo")
    public List<Object> hotelInfo(String hotelName,Integer pageNum){
//        System.out.println(hotelName);
//        System.out.println(pageNum);
        List<Object> hotelinfo = new ArrayList<>();
        List<HotelInfo> hotelInfos = hotelMapperService.findHotelInfoBYHotelName(hotelName);
        Integer id = hotelInfos.get(0).getId();
//        System.out.println(id+"111111111111");
//        if(id == null){
//            id = 1;
//        }
        Integer count = commentDao.findCommentsCountByHotelId(id);
//        System.out.println(count);
//        if (0 == count){
//            count = 1;
//        }
        List<HotelPolicy> hotelPolicies = hotelPolicyMapperService.selectPolicyByHotelName(hotelName);
        List<HotelFacilitiy> hotelFacilitiys = hotelFacilitiesMapperService.findHotelFacilityByHotelName(hotelName);
        List<HotelComment> hotelComments = commentDao.findHotelCommentByHotelId(id,pageNum);
//        Collections.reverse(hotelComments);
//        Collections.sort(hotelComments, Collections.reverseOrder());
        List<HotelComment> comments = commentDao.gettRecentCommentByHotelId(id);
        String cityName = hotelInfos.get(0).getCityName();
        List<RecentHotel> recentHotels = hotelMapperService.findRecentHotelByCity(cityName);
        hotelinfo.add(hotelInfos);
        hotelinfo.add(hotelPolicies);
        hotelinfo.add(hotelFacilitiys);
        hotelinfo.add(hotelComments);
        hotelinfo.add(comments);
        hotelinfo.add(recentHotels);
        hotelinfo.add(count);
        hotelinfo.add(commentDao.findGoodComment());
        return hotelinfo;
    }
}
